<template>
	<view class="body">
		<view class="bg">
			<image :src="$IMAGE_BASE_URL2 + '/yangcan/bg.png'"
				style="width: 100%; height:671rpx;margin: auto; display: block;"></image>
		</view>
		<view class="top">
			<u-navbar :border-bottom='false' title-color='#fff' back-icon-color='#fff' background="" title="星梦云康"
				:is-fixed='false'></u-navbar>
		</view>
		<view class="taideng top">
			<view class="title">
				<image :src="$IMAGE_BASE_URL + '/img/new/set.png'"
					style="width: 33rpx; height: 38rpx;float: left; margin: 20rpx 15rpx 0 15rpx ;">
				</image>
				星梦云康控制
				<!-- <image src="../../img/new/otherAdd.png"
					style="width: 46rpx; height: 46rpx;float: right; margin: 15rpx 15rpx 0 0 ;">
				</image> -->
			</view>
			<view class="info">
				<view>
					<view class="text">开关控制</view>
					<view class="mode">
						<u-row gutter="20">
							<u-col span="6">
								<view @click="sendCtl('SWITCH','one','bool')"
									:class="['choose', { modeActive: deviceInfo.SWITCH&&deviceInfo.SWITCH.value == 1 }]">
									开</view>
							</u-col>
							<u-col span="6">
								<view @click="sendCtl('SWITCH','zero','bool')"
									:class="['choose', { modeActive: deviceInfo.SWITCH&&deviceInfo.SWITCH.value == 0 }]">
									关</view>
							</u-col>
						</u-row>
					</view>
				</view>
				<view>
					<view class="text">模式选择</view>
					<view class="mode">
						<u-row gutter="20">
							<u-col span="4">
								<view @click="sendCtl('LIGHT',2,'enum')"
									:class="['choose', { modeActive: deviceInfo.LIGHT&&deviceInfo.LIGHT.value == 2 }]">
									全亮</view>
							</u-col>
							<u-col span="4">
								<view @click="sendCtl('LIGHT',1,'enum')"
									:class="['choose', { modeActive: deviceInfo.LIGHT&&deviceInfo.LIGHT.value == 1 }]">
									弱光</view>
							</u-col>
							<u-col span="4">
								<view @click="sendCtl('LIGHT',0,'enum')"
									:class="['choose', { modeActive: deviceInfo.LIGHT&&deviceInfo.LIGHT.value == 0 }]">
									睡眠</view>
							</u-col>
						</u-row>
					</view>
				</view>
				<!-- <view>
					<view class="text">亮度调节</view>
					<view style="margin: 30rpx 0;">
						<u-slider v-model="value" height="28" active-color="#ffe53a" block-color='#d9dfe8'></u-slider>
					</view>
				</view> -->
			</view>
		</view>
		<view class="taideng" style="margin-top: 40rpx;">
			<view class="title">
				<image :src="$IMAGE_BASE_URL + '/img/new/tixing.png'"
					style="width: 39rpx; height: 41rpx;float: left; margin: 20rpx 15rpx 0 15rpx ;">
				</image>
				健康提醒
				<image @click="showaddRemind=true" :src="$IMAGE_BASE_URL + '/img/new/otherAdd.png'"
					style="width: 46rpx; height: 46rpx;float: right; margin: 15rpx 15rpx 0 0 ;">
				</image>
			</view>
			<view class="info tixing condition">
				<view class="list2" v-if="tixing.length == 0">
					请先添加提醒
				</view>
				<!--  -->
				<u-swipe-action style="margin-bottom: 20rpx;display: block;" :show="data.show" :index="dataIndex"
					v-for="(data, dataIndex) in tixing" :key="dataIndex" @click="Scenedel(data)" @open="open(dataIndex)"
					:options="options">
					<view class="list">
						<text
							class="time">{{data.condition.hour}}:{{data.condition.minute<10?"0"+data.condition.minute:data.condition.minute}}</text>
						{{data.sceneName}}
						<switch class="switch" @change="e=>tixingchange(e,data)" :checked="data.inUse" color="#0dd30c"
							style="transform:scale(0.8)" />
						<!-- <u-switch class="switch" @ v-model="data.inUse" active-color="#0dd30c"></u-switch> -->
						<view class="logicFrequency">频次：{{data.logicFrequency}}</view>
					</view>
				</u-swipe-action>
			</view>
		</view>
		<view class="taideng" style="margin-top: 40rpx;">
			<view class="title">
				<image src='@/img/new/miandarao.png'
					style="width: 39rpx; height: 41rpx;float: left; margin: 20rpx 15rpx 0 15rpx ;">
				</image>
				睡眠免打扰
				<image @click="showaddMDR=true" src='@/img/new/set1.png'
					style="width: 46rpx; height: 46rpx;float: right; margin: 15rpx 15rpx 0 0 ;">
				</image>
			</view>
			<view class="info tixing condition">
				起始时间
				<view style="clear: both;margin-top: 20rpx;"></view>
				<view class="list2" style="float: left; width: 240rpx;text-align: center;display: block;">
					{{MDRTime.startTime}}
				</view>
				<view class="list2" style="float: right; width: 240rpx;text-align: center;display: block;">
					{{MDRTime.endTime}}
				</view>
			</view>
		</view>
		<view class="taideng" style="margin-top: 40rpx;">
			<view class="title">
				<image :src="$IMAGE_BASE_URL + '/img/new/jjlxr.png'"
					style="width: 39rpx; height: 41rpx;float: left; margin: 20rpx 15rpx 0 15rpx ;">
				</image>
				紧急联系人
				<!-- <image src="../../img/new/otherAdd.png"
					style="width: 46rpx; height: 46rpx;float: right; margin: 15rpx 15rpx 0 0 ;">
				</image> -->
			</view>
			<view class="info tixing">
				<!-- <view class="list2" v-if="!deviceInfo.NUM_1&&!deviceInfo.NUM_2">
					请先添加紧急联系人
				</view> -->
				<view class="list2" @click="isshowContacts(deviceInfo.NUM_1?deviceInfo.NUM_1.value:'','NUM_1')">
					{{deviceInfo.NUM_1?deviceInfo.NUM_1.value?deviceInfo.NUM_1.value:'添加紧急联系人1':'添加紧急联系人1'}}
					<u-icon name="edit-pen-fill" color="#ff720a" size="28" style="margin-left: auto;"></u-icon>
				</view>
				<view class="list2" @click="isshowContacts(deviceInfo.NUM_2?deviceInfo.NUM_2.value:'','NUM_2')">
					{{deviceInfo.NUM_2?deviceInfo.NUM_2.value?deviceInfo.NUM_2.value:'添加紧急联系人2':'添加紧急联系人2'}}
					<u-icon name="edit-pen-fill" color="#ff720a" size="28" style="margin-left: auto;"></u-icon>
				</view>
				<!-- <view class="list2">
					张某某
					<text class="time" style="margin-left: auto;">15167541111</text>
				</view>
				<view class="list2">
					张某某
					<text class="time" style="margin-left: auto;">15167541111</text>
				</view> -->
			</view>
		</view>
		<!-- <view class="taideng" style="margin-top: 40rpx;">
			<view class="title">
				<image :src="$IMAGE_BASE_URL + '/img/new/wang.png'"
					style="width: 40rpx; height: 40rpx;float: left; margin: 20rpx 15rpx 0 15rpx ;">
				</image>
				联网模式
			</view>
			<view class="info tixing">
				<view class="mode">
					<u-row gutter="20">
						<u-col span="6">
							<view :class="['choose', { active: deviceInfo.UP_MODE&&deviceInfo.UP_MODE.value == 1 }]">4G
							</view>
						</u-col>
						<u-col span="6">
							<view :class="['choose', { active: deviceInfo.UP_MODE&&deviceInfo.UP_MODE.value == 0 }]">
								WIFI</view>
						</u-col>
					</u-row>
				</view>
			</view>
		</view> -->
		<view class="taideng" style="margin: 40rpx 0;">
			<view class="title">
				<image :src="$IMAGE_BASE_URL + '/img/new/wifi.png'"
					style="width: 50rpx; height: 35rpx;float: left; margin: 20rpx 15rpx 0 15rpx ;">
				</image>
				WIFI配网
			</view>
			<view class="info tixing">
				<view class="peiwang" @click="onSetConfigWifi">配网</view>
				<view class="list2">
					{{deviceInfo.ConnectWiFi?deviceInfo.ConnectWiFi.value:'--'}}
					<u-icon v-if="deviceInfo.ConnectWiFi" name="checkbox-mark" color="#0dd30c"
						style="margin-left: auto;" size="28"></u-icon>
				</view>
			</view>
		</view>
		<!-- <u-input v-model="typeSelect.current.label" type="select" @click="typeSelect.show=true" /> -->
		<u-popup v-model="showaddRemind" mode="center" border-radius="15" width="80%" z-index="888">
			<view class="popup">
				<view style="font-size: 36rpx;" class="bai">新增提醒</view>
				<u-form :model="addRemind" ref="addRemind" label-position="top">
					<u-form-item label="提醒时间" prop="time">
						<view class="input">
							<picker mode="time" :value="addRemind.time" start="00:00" end="23:59"
								@change="bindTimeChange">
								{{addRemind.time!=''?addRemind.time:'请选择时间'}}
							</picker>
						</view>
					</u-form-item>
					<u-form-item label="提醒频次" prop="checkbox">
						<u-checkbox-group v-model="addRemind.checkbox">
							<u-checkbox v-model="item.checked" v-for="(item, index) in weekList" :key="index"
								:name="item.name">
								{{ item.name }}
							</u-checkbox>
						</u-checkbox-group>
					</u-form-item>
					<u-form-item label="提醒类型" prop="sceneTypeId">
						<view class="input">
							<u-input v-model="typeSelect.current.label" type="select" @click="typeSelect.show=true" />
							<!-- <u-input v-model="typeSelect.current.label" :type="type" @click="typeSelect.show=true" />
							<u-action-sheet :list="typeSelect.list" v-model="typeSelect.show" @click="onTypeSelect"></u-action-sheet> -->
						</view>
					</u-form-item>
					<u-form-item v-if="childTypeSelect.list.length > 1" label="提醒内容" prop="childType">
						<view class="input">
							<u-input v-model="childTypeSelect.current.label" type="select"
								@click="childTypeSelect.show=true" />
						</view>
					</u-form-item>

					<u-button @click="submit" type="warning">提交</u-button>
				</u-form>
			</view>
		</u-popup>
		<u-popup v-model="showaddMDR" mode="center" border-radius="15" width="80%" z-index="888">
			<view class="popup">
				<view style="font-size: 36rpx;" class="bai">修改时间</view>
				<u-form label-position="top">
					<u-form-item label="起始时间">
						<view class="input">
							<picker mode="time" :value="MDRTime.startTime" start="00:00" end="23:59"
								@change="MDRStartTimeChange">
								{{MDRTime.startTime}}
							</picker>
						</view>
					</u-form-item>
					<u-form-item label="结束时间">
						<view class="input">
							<picker mode="time" :value="MDRTime.endTime" start="00:00" end="23:59"
								@change="MDREndTimeChange">
								{{MDRTime.endTime}}
							</picker>
						</view>
					</u-form-item>
					<u-button @click="submitMdrTime" type="warning">提交</u-button>
				</u-form>
			</view>
		</u-popup>
		<u-popup v-model="showContacts" mode="center" border-radius="15" width="80%" z-index="888">
			<view class="popup">
				<!-- <view>紧急联系人</view> -->
				<u-form :model="Contacts" ref="Contacts" label-position="top">
					<u-form-item :label="Contacts.num === 'NUM_1' ? '联系人电话1' : '联系人电话2'" prop="phone">
						<view class="input">
							<u-input v-model="Contacts.phone" type="number" />
						</view>
					</u-form-item>
					<u-button @click="submitContacts" type="warning">提交</u-button>
				</u-form>
			</view>
		</u-popup>
		<u-toast ref="uToast1" />
		<u-select v-model="typeSelect.show" :list="typeSelect.list" @confirm="onTypeSelect"></u-select>
		<u-select v-model="childTypeSelect.show" :list="childTypeSelect.list" @confirm="onchildTypeSelect"></u-select>
	</view>
</template>

<script>
	import {
		getSceneType,
		postScenenotify,
		getScenenotify,
		putScene,
		getPropert,
		getdeviceSet,
		delScene
	} from "@/api/device/index.js";
	import {
		getCurrentPage
	} from '@/core/app'
	import StorageUtils from "@/utils/StorageUtils";
	import SimDevice from '../../service/mqtt/sim/SimDevice.js';
	import {
		DeviceBasicData
	} from '../../service/mqtt/DeviceConfig.js';
	export default {
		data() {
			return {
				deviceId: '',
				deviceName: '',
				disabled: false,
				btnWidth: 180,
				show: false,
				options: [{
					text: '删除',
					style: {
						backgroundColor: '#dd524d'
					}
				}],
				showaddMDR: false,
				MDRTime: { //免打扰时间
					startTime: '--:--',
					endTime: '--:--'
				},
				deviceInfo: {
					SWTICH: null,
					LIGHT: null,
					NUM_1: null,
					NUM_2: null,
				}, //设备信息
				list: [{
						name: '暖色'
					},
					{
						name: '冷色'
					}
				],
				addRemind: {
					time: this.$u.timeFormat(new Date(), 'hh:MM'),
					hour: this.$u.timeFormat(new Date(), 'hh'),
					minute: this.$u.timeFormat(new Date(), 'MM'),
					checkbox: '',
					sceneTypeId: '',
					childType: '',
					userId: StorageUtils.get('uuid')
				}, //新增提醒
				Contacts: {
					phone: '',
					num: '', //紧急联系人第几
				}, //紧急联系人
				showaddRemind: false,
				showContacts: false,
				checked: false,
				current: 1,
				list2: [{
						name: '阅读模式'
					},
					{
						name: '休息模式'
					}
				],
				tixing: [],
				weekList: [{
						name: '周一',
					},
					{
						name: '周二',
					},
					{
						name: '周三',
					},
					{
						name: '周四',
					},
					{
						name: '周五',
					},
					{
						name: '周六',
					},
					{
						name: '周日',
					}
				],
				current2: 1,
				value: 30,
				rules: {
					time: [{
						required: true,
						message: '请选择时间',
						trigger: ['change', 'blur']
					}],
					childType: [{
						required: true,
						message: '请选择提醒内容',
						trigger: ['change', 'blur']
					}],
					sceneTypeId: [{
						type: "number",
						required: true,
						message: '请选择提醒类型',
						trigger: ['change']
					}],
					phone: [{
							type: "number",
							required: true,
							message: '请填写电话号码',
							trigger: ['change', 'blur']
						},
						{
							// 自定义验证函数，见上说明
							validator: (rule, value, callback) => {
								// 上面有说，返回true表示校验通过，返回false表示不通过
								// this.$u.test.mobile()就是返回true或者false的
								return this.$u.test.mobile(value);
							},
							message: '手机号码不正确',
							// 触发器可以同时用blur和change
							trigger: ['change', 'blur'],
						}
					],
					checkbox: [{
						type: "array",
						required: true,
						message: '请选择频次',
						trigger: ['blur']
					}]
				},
				typeSelect: {
					show: false,
					current: {},
					list: [],
				},
				childTypeSelect: {
					show: false,
					current: {},
					list: [],
				},
			}
		},
		onShow() {
			this.deviceId = getCurrentPage().query.iotDeviceId;
			this.deviceName = decodeURIComponent(getCurrentPage().query.deviceName);
			// console.log("this.deviceName", decodeURIComponent(getCurrentPage().query.deviceName));
			// console.log(getCurrentPage().query);
			if (!this.deviceId) {
				return false;
			}
			getSceneType({}).then(res => {
				let list = []
				res.obj.map(v => {
					list.push({
						value: v.id,
						label: v.notifyType,
						childType: v.childType.split(',')
					})
				})
				this.typeSelect.list = list
			})
			this.Scenenotify()
			this.Propert()
			this.mqtt()
		},
		onPullDownRefresh() {
			// 下拉刷新时重新获取数据
			getPropert({
				deviceId: this.deviceId
			}).then(res => {
				if (res.obj.NODISTURB_TIME) {
					if (res.obj.NODISTURB_TIME.value != '') {
						this.MDRTime = { //免打扰时间
							startTime: res.obj.NODISTURB_TIME.value.split('-')[0],
							endTime: res.obj.NODISTURB_TIME.value.split('-')[1]
						}
					}
				}
				this.deviceInfo = res.obj;
				// this.simDevice.close();
				if (this.mqttPing) {
					clearInterval(this.mqttPing);
					this.simDevice.close();
				}
				this.mqtt()
				uni.stopPullDownRefresh();
			})
		},
		onHide() {
			if (this.mqttPing) {
				clearInterval(this.mqttPing);
				this.simDevice.close();
			}
		},
		onUnload() {
			if (this.mqttPing) {
				clearInterval(this.mqttPing);
				this.simDevice.close();
			}
		},
		methods: {
			Scenedel(index, index1) {
				delScene({
					sceneId: index.id
				}).then(res => {
					this.Scenenotify();
				})
			},
			mqtt() {
				let deviceBasicData = new DeviceBasicData('', '', undefined);
				this.simDevice = new SimDevice();
				let url = '47.97.72.174:1887';
				// let url = '123.60.177.231:1887';
				deviceBasicData.username = '1559108322@qq.com';
				deviceBasicData.password = '123456';
				deviceBasicData.addr = url;
				let that = this;
				this.simDevice.clientDataListener = {
					onHandle: (topic, msg) => {
						msg = msg.replace(/'/g, '"');
						if (JSON.parse(msg).method === 'thing.service.property.post') {
							let info = JSON.parse(msg);
							let item = info.params;
							if (item == undefined) {
								return false;
							}
							this.deviceInfo = {
								...this.deviceInfo,
								...item
							}
							// console.log(this.deviceInfo);
						}
					},
					onSetProperty: (requestPayload) => {
						let params = requestPayload.params;
					},
					onConnect(success) {
						// console.log('连接服务器:' + success);
						if (success) {
							that.simDevice.subscribe('r57gjbjAKEY', decodeURIComponent(getCurrentPage().query
								.deviceName))
							that.mqttPing = setInterval(() => {
								that.simDevice.ping()
							}, 30000);
						}
					},
					onClose() {
						console.log('连接关闭');
					}
				};
				this.simDevice.init(deviceBasicData);
				this.simDevice.connectServer();
			},
			// 如果打开一个的时候，不需要关闭其他，则无需实现本方法
			open(index) {
				// 先将正在被操作的swipeAction标记为打开状态，否则由于props的特性限制，
				// 原本为'false'，再次设置为'false'会无效
				this.tixing[index].show = true;
				this.tixing.map((val, idx) => {
					if (index != idx) this.tixing[idx].show = false;
				})
			},
			Scenenotify() {
				getScenenotify({
					uuid: StorageUtils.get('uuid')
				}).then(res => {
					let tixing = []
					tixing = res.obj.map(v => {
						let weekdayMap = {
							'MONDAY': '周一',
							'TUESDAY': '周二',
							'WEDNESDAY': '周三',
							'THURSDAY': '周四',
							'FRIDAY': '周五',
							'SATURDAY': '周六',
							'SUNDAY': '周日'
						};
						const dayOrder = {
							MONDAY: 1,
							TUESDAY: 2,
							WEDNESDAY: 3,
							THURSDAY: 4,
							FRIDAY: 5,
							SATURDAY: 6,
							SUNDAY: 7
						};
						let condition = JSON.parse(v.conditionJson)[0]
						// 自定义排序函数
						let sortedDays = condition.logicFrequency.sort((a, b) => dayOrder[a] - dayOrder[
							b]);
						let logicFrequency = condition.logicFrequency.map(day => weekdayMap[day]);
						return {
							...v,
							condition: condition,
							show: false,
							logicFrequency: logicFrequency.join('，')
						}
					})
					this.tixing = tixing
					this.tixing.map((val, idx) => {
						this.tixing[idx].show = false;
					})
				})
			},
			showAddReminds(obj) {
				this.showaddRemind = true;
				this.childTypeSelect = {
					show: false,
					current: {},
					list: [],
				}
				this.typeSelect = {
					...this.typeSelect,
					show: false,
					current: {}
				}
				this.addRemind.childType = ''
			},
			isshowContacts(obj, num) {
				if (!this.deviceInfo.NUM_1 && num == 'NUM_2') {
					this.$refs.uToast1.show({
						title: '请先添加紧急联系人1',
						type: 'warning'
					})
					return false;
				}
				if (!this.deviceInfo.NUM_1.value && num == 'NUM_2') {
					this.$refs.uToast1.show({
						title: '请先添加紧急联系人1',
						type: 'warning'
					})
					return false;
				}
				this.showContacts = true;
				this.Contacts = {
					phone: obj,
					num
				}
			},
			Propert(obj) {
				getPropert({
					deviceId: this.deviceId
				}).then(res => {
					if (res.obj.NODISTURB_TIME) {
						if (res.obj.NODISTURB_TIME.value != '') {
							this.MDRTime = { //免打扰时间
								startTime: res.obj.NODISTURB_TIME.value.split('-')[0],
								endTime: res.obj.NODISTURB_TIME.value.split('-')[1]
							}
						}
					}
					this.deviceInfo = res.obj;
					if (obj == 'SWITCH') {
						this.sendCtl('LIGHT', this.deviceInfo.LIGHT.value, 'enum')
					}
				})
			},
			tixingchange(e, data) {
				putScene({
					inUse: e.detail.value,
					sceneId: data.id
				}).then(res => {

				})
			},
			sendCtl(identifiers, value, type) {
				if (this.deviceInfo.work_mode.value == 1) {
					this.$refs.uToast1.show({
						title: '请先退出夜灯模式！',
						type: 'warning'
					})
					return false;
				}
				if (identifiers == 'LIGHT' && this.deviceInfo.SWITCH.value == 0) {
					this.$refs.uToast1.show({
						title: '请先开灯！',
						type: 'warning'
					})
					return false;
				}
				getdeviceSet({
					value,
					deviceName: this.deviceName,
					identifier: identifiers,
					productKey: 'r57gjbjAKEY',
					type,
				}).then(res => {
					this.showaddMDR = false;
					if (identifiers == 'SWITCH' && value == 'one') {
						this.Propert('SWITCH')
					} else {
						this.Propert()
					}
				}).catch(res => {
					// if (identifiers == 'SWITCH' && value == 'one') {
					// 	this.sendCtl('LIGHT', this.deviceInfo.LIGHT.value, 'enum')
					// }
					// this.Propert()
					// this.$refs.uToast1.show({
					// 	title: res.msg,
					// 	type: 'error'
					// })
				})
			},
			submit() {
				this.$refs.addRemind.setRules(this.rules);
				this.$refs.addRemind.validate(valid => {
					console.log(this.$refs.addRemind);
					console.log(valid);
					if (valid) {
						let weekdayMap = {
							'周一': 'MONDAY',
							'周二': 'TUESDAY',
							'周三': 'WEDNESDAY',
							'周四': 'THURSDAY',
							'周五': 'FRIDAY',
							'周六': 'SATURDAY',
							'周日': 'SUNDAY'
						};
						// this.addRemind.childType=this.childTypeSelect.current.lable?this.childTypeSelect.current.lable:''
						this.addRemind.frequency = this.addRemind.checkbox.map(day => weekdayMap[day]);
						postScenenotify(this.addRemind).then(res => {
							if (res.code == '0000') {
								this.showaddRemind = false
								this.Scenenotify()
								this.$refs.uToast1.show({
									title: '成功！',
									type: 'success'
								})
							}

						})
					} else {
						console.log('验证失败');
					}
				});
			},
			submitContacts() { //修改紧急联系人
				this.$refs.Contacts.setRules(this.rules);
				this.$refs.Contacts.validate(valid => {
					if (valid) {
						this.showContacts = false;
						this.sendCtl(this.Contacts.num, this.Contacts.phone, 'string')
					} else {
						console.log('验证失败');
					}
				});
			},
			onTypeSelect(arr) {
				let current = arr[0];
				let value = current.value;
				this.typeSelect.current = current;
				this.addRemind.sceneTypeId = value;
				let list = []
				this.typeSelect.list.map(v => {
					if (value == v.value && v.childType.length > 1) {
						v.childType.map(v => {
							list.push({
								value: v,
								label: v,
							})
						})
					}
				})
				this.childTypeSelect.list = list;
				this.childTypeSelect.current = {}
				this.addRemind.childType = ''
			},
			onchildTypeSelect(arr) {
				let current = arr[0];
				let value = current.value;
				this.childTypeSelect.current = current;
				this.addRemind.childType = value;
			},
			bindTimeChange: function(e) {
				this.addRemind.hour = e.detail.value.split(':')[0]
				this.addRemind.minute = e.detail.value.split(':')[1]
				this.addRemind.time = e.detail.value;
			},
			MDRStartTimeChange: function(e) { //免打扰起始时间
				this.MDRTime.startTime = e.detail.value
			},
			MDREndTimeChange: function(e) { //免打扰结束时间
				this.MDRTime.endTime = e.detail.value
			},
			submitMdrTime() { //修改免打扰
				this.showContacts = false;
				this.sendCtl('NODISTURB_TIME', this.MDRTime.startTime + '-' + this.MDRTime.endTime, 'string')
				this.sendCtl('RADAR', this.outfilter(this.MDRTime.startTime.split(':')[0] * 1, this.MDRTime.startTime
					.split(':')[1] * 1, 0, this.MDRTime.endTime.split(':')[0] * 1, this.MDRTime.endTime.split(':')[
						1] * 1, 0), 'string')
			},
			outfilter(a, b, c, d, e, f) {
				let res = "55aa6a06" + a.toString(16).padStart(2, '0') +
					b.toString(16).padStart(2, '0') +
					c.toString(16).padStart(2, '0') +
					d.toString(16).padStart(2, '0') +
					e.toString(16).padStart(2, '0') +
					f.toString(16).padStart(2, '0');
				res = res + this.addLast2Hex(res);
				return res;
			},
			addLast2Hex(str) {
				let sum = 0;
				for (let i = 0; i < str.length; i++) {
					const char = str.charAt(i);
					if (i % 2 === 0) {
						// 高位字符 (乘以16)
						sum += parseInt(char, 16) * 16;
					} else {
						// 低位字符
						sum += parseInt(char, 16);
					}
				}
				// 将总和转换为两个字节的十六进制字符串
				return this.toHexStr(Math.floor(sum / 256)) + this.toHexStr(sum % 256);
			},
			toHexStr(num) {
				return num.toString(16).padStart(2, '0');
			},
			onSetConfigWifi() {
				const param = {
					deviceId: this.deviceId,
					deviceName: this.deviceName,
					productKey: 'r57gjbjAKEY',
				}
				console.log("onSetConfigWifi param", param);
				this.$addDeviceService.resetLightConfigWifi(param);
			}
		}
	}
</script>
<style lang="scss">
	.bg {
		position: absolute;
		top: 0;
		left: 0;
		width: 100%;
	}

	.top {
		position: relative;
		z-index: 99;
	}

	.uni-picker-container {
		z-index: 999999 !important;
	}

	.body {
		// padding: 0 0 0;
		color: #040303;
		background-color: #fff;

		.popup {
			padding: 30rpx;
			background: linear-gradient(to bottom, #ff720a, #ffffff) 0 0 / 100% 300rpx no-repeat;

			.bai {
				color: #fff;
			}
		}

		.input {
			background-color: #fff;
			width: 100%;
			box-shadow: 0 1rpx 44rpx rgba(169, 169, 169, .3);
			text-align: center;
			border-radius: 20rpx;
			padding: 0rpx 20rpx;
			// box-shadow: 0px 0px 10rpx rgba(0, 0, 0, 0.5);
		}
	}

	.text {
		font-weight: bold;
		line-height: 2;
	}

	.lianxi {
		background-color: #fff;
		padding: 20rpx;
		overflow: hidden;

		.fl {
			float: left;
			line-height: 2;

		}

		.fr {
			float: right;
			line-height: 2;
		}
	}

	.mb {
		margin-bottom: 30rpx;
	}

	.taideng {
		margin-top: 20rpx;
		padding: 0 20rpx 20rpx 20rpx;
		font-size: 36rpx;
		overflow: hidden;

		.title {
			font-size: 36rpx;
			line-height: 76rpx;
		}

		.w50 {
			float: left;
			width: 48%;

			.data {
				width: 100%;
				text-align: center;
			}
		}

		.mr4 {
			margin-right: 4%;
		}

		.text {
			font-size: 28rpx;
		}

		.info {
			margin-bottom: 10px;
			background-color: #fff;
			padding: 30rpx;
			border-radius: 30rpx;
			// overflow: hidden;
			margin: 10rpx;
			position: relative;
			font-size: 36rpx;
			box-shadow: 3px 3px 3px rgba(0, 0, 0, 0.1), -1px -1px 3px rgba(0, 0, 0, 0.1);
			overflow: hidden;

		}

		.tixing {
			.peiwang {
				background-color: #0dd30c;
				color: #fff;
				margin: 20rpx;
				margin-left: auto;
				line-height: 52rpx;
				width: 130rpx;
				border-radius: 8rpx;
				text-align: center;
				font-size: 28rpx;
			}

			.list2 {
				margin-bottom: 20rpx;
				font-size: 32rpx;
				display: flex;
				background-color: #f2f2f2;
				line-height: 80rpx;
				border-radius: 10rpx;
				padding: 0 20rpx;
				position: relative;

				.time {
					color: #848484;
					font-size: 30rpx;
					margin-right: 20rpx;
				}
			}

			.list {
				margin-bottom: 20rpx;
				font-size: 32rpx;
				// display: flex;
				background-color: #f2f2f2;
				line-height: 80rpx;
				border-radius: 10rpx;
				padding: 0 20rpx 20rpx 20rpx;
				position: relative;

				.time {
					color: #848484;
					font-size: 30rpx;
					margin-right: 20rpx;
				}
			}

			.list:last-child {
				margin-bottom: 0;
			}

			.list2:last-child {
				margin-bottom: 0;
			}

			.logicFrequency {
				font-size: 24rpx;
				line-height: 24rpx;
			}

			.switch {
				position: absolute;
				top: 0;
				right: 30rpx;
			}
		}

		.mode {
			margin: 30rpx;

			.choose {
				background-color: #f2f5f8;
				height: 86rpx;
				border-radius: 10rpx;
				text-align: center;
				line-height: 86rpx;
				box-shadow: 3px 3px 3px rgba(0, 0, 0, 0.1), -1px -1px 3px rgba(0, 0, 0, 0.1);
				font-size: 26rpx;
			}

			.active {
				background-color: #0dd30c;
				color: #fff;
			}

			.modeActive {
				background-color: #f67507;
				color: #fff;
			}
		}

	}

	.u-select {
		z-index: 99999999;
		width: 100%;
	}
</style>